package com.sky.web.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.SetmealVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/setmeal")
public class SetmealController {
    @Autowired
    private SetmealService setmealService;
    @PostMapping
    @CacheEvict(value = "setmeal" ,allEntries = true)
    public Result save(@RequestBody SetmealDTO setmealDTO){
        setmealService.save(setmealDTO);
        return Result.success();
    }

    @GetMapping("page")
    public Result findByPage(SetmealPageDTO dto){
           PageResult pageResult = setmealService.findByPage(dto);
        return Result.success(pageResult);
    }

    @GetMapping("{id}")
    public Result findById(@PathVariable Long id){
            SetmealVO vo = setmealService.findById(id);
        return Result.success(vo);
    }

    @PutMapping
    @CacheEvict(value = "setmeal" ,allEntries = true)
    public Result update(@RequestBody SetmealDTO dto){
        setmealService.update(dto);
        return Result.success();
    }

    @DeleteMapping
    @CacheEvict(value = "setmeal" ,allEntries = true)
    public Result deleteByIds(Long[] ids){
        setmealService.deleteByIds(ids);
        return Result.success();
    }

    @PostMapping("/status/{status}")
    @CacheEvict(value = "setmeal" ,allEntries = true)
    public Result updateStatus(@PathVariable Integer status,Long id){

        setmealService.updateStatus(status,id);
        return Result.success();
    }
}
